//
//  ApplyPhotoModel.swift
//  LongTermInsurance
//
//  Created by zolobdz on 2018/12/8.
//  Copyright © 2018年 HeChao. All rights reserved.
//

import UIKit
import ObjectMapper

class ApplyPhotoModel: NSObject, Mappable {
    
    // 存储属性，需要存到本地
    
    var uploaded = false
    var isRemote = false // 为true时,表示用户已经上传了的照片（修改申请的情况下），data为nil
    var name = ""
    var data: Data?
    
    // getter 属性
    
    var fullPathName: String {
        let temp = "\(NetworkingHandle.main)/Upload/\(name)"
        return temp
    }
    
    var image: UIImage? {
        get {
            return data != nil ? UIImage(data: data! as Data) : nil
        }
        set {
            if newValue != nil, let d = UIImagePNGRepresentation(newValue!){
                self.data = d
            } else {
                self.data = nil
            }
        }
    }

    override init() {

    }
    
    required init?(map: Map) {
        
    }
    
    func mapping(map: Map) {
        name <- map["name"]
        isRemote <- map["isRemote"]
        uploaded <- map["uploaded"]
        data <- map["data"]
    }
}

class ApplyPhotoRemoteModel: NSObject, Mappable {
    
    var type = ""
    var name = ""
    
    override init() {
        
    }
    
    required init?(map: Map) {
        
    }
    
    func mapping(map: Map) {
        type <- map["fjlx"]
        name <- map["wjmc"]
//        data <- map["wjlj"]
    }
    
//    "fjlx\":78.0,\ 图片
//    "wjmc\":\"9b6f6b57bc0b.png\",\
//    "wjlj\":\"../upload/9b6f6b57bc0b.png\"}
}
